home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 43 / Mac Magazin and MacEasy Magazine CD - Issue 43.iso / Software / Mobiles Büro / Newton / Newton Entwickler / DIL 2.0 Sample Code ƒ / SoupDrink-Mac-4 / DILCPIPE.H < prev    next >
Text File  |  1995-12-21  |  11KB  |  248 lines

  1. /*
  2.     File:        DILCPipe.h
  3.  
  4.     Contains:    C Definitions of the DIL Pipe class
  5.  
  6.     Written by:    Rob Langhorne
  7.  
  8.     Copyright:    c 1995 by Apple Computer, Inc.  All rights reserved.
  9.  
  10.     Change History (most recent first): 
  11.             version 1.0 Universal CDIL Headers
  12.     To Do:
  13.  
  14. */
  15.  
  16. #ifndef __DILCPIPE_H
  17. #define __DILCPIPE_H
  18.  
  19. #if GENERATINGPOWERPC
  20. #pragma options align=mac68k
  21. #endif
  22.  
  23. /*-------------------------------------------------------------------------
  24. **
  25. **    Definitions
  26. **
  27. ** ------------------------------------------------------------------------ */
  28.  
  29. /*-------------------------------------------------------------------------
  30. **    Compatibility definitions    
  31. ** ------------------------------------------------------------------------ */
  32. #ifdef forMac
  33.     #define FAR
  34.     #define PASCAL
  35.     #define _export 
  36.     
  37.     #include <Types.h>
  38. #else
  39.     typedef unsigned char Boolean;
  40.     #define nil NULL
  41.     #define true TRUE
  42.     #define false FALSE
  43.     typedef long Size;
  44.  
  45.     #ifndef forWin16
  46.         #define _export 
  47.         #define FAR
  48.     #endif
  49.  
  50. #endif
  51.  
  52. /*-------------------------------------------------------------------------
  53. **    Local Error Codes    
  54. ** ------------------------------------------------------------------------ */
  55.  
  56. #define kDILErrBase                     (-700 + -28000)                /*    Error code base number                */
  57.  
  58. #define kCommErrNoErr                    0                                            /*    No error                                                    */
  59. #define kOutOfMemory                    (-1 + kDILErrBase)        /*    Error on memory allocation                */
  60. #define kBadPipeState                    (-2 + kDILErrBase)        /*    DIL Pipe was set to a bad state        */
  61. #define kExceptionErr                    (-3 + kDILErrBase)        /*    An unhandled exception was raised    */
  62. #define kQueueFullError                (-4 + kDILErrBase)        /*    async completion queue is full        */
  63. #define kPipeNotInitialized        (-5 + kDILErrBase)        /*    Pipe has not been initialized            */
  64. #define kInvalidParameter            (-6 + kDILErrBase)        /*    A parameter passed in was invalid    */
  65. #define kPipeNotReady                    (-7 + kDILErrBase)        /*    Pipe is not ready for operation        */
  66. #define kTimeout                            (-8 + kDILErrBase)        /*     A timeout has occurred                        */
  67.  
  68. /*-------------------------------------------------------------------------
  69. **    CDIL State type    
  70. **        The following enumeration is used to identify the state of the
  71. **        current CDIL Pipe.
  72. ** ------------------------------------------------------------------------ */
  73.  
  74. typedef enum CDIL_State {
  75.     kCDIL_Uninitialized = 0,    /*    0 CDIL is uninitialized                                                      */
  76.     kCDIL_InvalidConnection,    /*  1 CDIL tried to bring up connection, but it failed    */
  77.     kCDIL_Disconnected,              /*    2 CDIL is not connected                                                      */
  78.     kCDIL_Listening,                /*    3 CDIL is listening for a connection                                */
  79.     kCDIL_ConnectPending,          /*    4 A connection is pending                                                    */
  80.     kCDIL_Connected,                /*    5 CDIL is connected                                                            */
  81.     kCDIL_Busy,                          /*    6 CDIL is either reading or writing                                     */
  82.     kCDIL_Aborting,                    /*    7 CDIL is currently aborting                                              */
  83.     kCDIL_Startup,                    /*    8 CDIL is currently starting up                                          */
  84.     kCDIL_Userstate = 50          /*    50 Users can add CDIL states after this point              */
  85. } CDIL_State;
  86.  
  87. /*-------------------------------------------------------------------------
  88. **    Unicode encoding definitions (from Unicode.h) -> Just documenting the 
  89. **                currently available values here
  90. typedef enum {
  91.     kUnicode = 0,                    // not implemented
  92.     kMacRomanEncoding,            // Macintosh Roman
  93.     kPCRomanEncoding = 3,        // PC Roman
  94. } TCharEncoding;
  95. ** ------------------------------------------------------------------------ */
  96.  
  97. /*-------------------------------------------------------------------------
  98. **    Pipe direction definitions    
  99. ** ------------------------------------------------------------------------ */
  100.  
  101. typedef enum CDILPipeDirection {
  102.     kUndefinedDirection = 0,
  103.     kReadPipe,                    /*    Read pipe direction                                */
  104.     kWritePipe,                    /*    Write pipe direction                            */
  105.     kAllPipes                      /*    Apply to all pipes (where applicable)    */
  106. } CDILPipeDirection;
  107.  
  108. typedef void FAR CDILPipe;
  109.  
  110. /*-------------------------------------------------------------------------
  111. **    Other definitions    
  112. ** ------------------------------------------------------------------------ */
  113. #ifdef forMac
  114.     #define kDefaultTimeout     60*30    /*    Default timeout for DIL operations    */
  115. #else    // for Windows
  116.     #define kDefaultTimeout     1000    /*    Default timeout for DIL operations    */
  117. #endif
  118. #define    kDefaultBufferSize    1024        /*    Default buffer size for DIL I/O        */
  119.  
  120. typedef long CommErr;                    /* Comm Error Code                        */
  121.  
  122. /*------------------------------------------------------------------------------------
  123. **    Completion function definitions
  124. **        Completion functions and other function pointers that are used by CDILs
  125. **        should conform to one of the following type definitions.  
  126. **        
  127. **        These are:
  128. **            CDILCompletionProcPtr -  the basic callback function definition.  This
  129. **                                    is used by CDPipeListen() and CDPipeWrite().
  130. **        
  131. **            CDILPipeCompletionProcPtr - the read callback function definition.  Any
  132. **                                    data returned is in the buffer pointed to by
  133. **                                    the pData parameter.  This is used by CDPipeRead().
  134. **        
  135. **            CDILEncryptionProcPtr -  This points to an encryption callback hook.  
  136. **                                    This can be used to encrypt the data stream using
  137. **                                    the user-defined algorithm just prior to 
  138. **                                    putting the data on the wire.
  139. **        
  140. **            CDILDecryptionProcPtr -  This points to an decryption callback hook.  
  141. **                                    This can be used to decrypt the data stream using
  142. **                                    the user-defined algorithm just after the 
  143. **                                    data is pulled off the wire.
  144. ** ----------------------------------------------------------------------------------- */
  145. typedef void (FAR *CDILCompletionProcPtr)( CommErr errorValue, long refCon ) ;
  146. typedef void (FAR *CDILPipeCompletionProcPtr)( CommErr errorValue, void FAR *pData, long Count, long refCon, long lFlags ) ;
  147. typedef CommErr (FAR *CDILEncryptionProcPtr)( void FAR *pData, long Count, long refCon ) ;
  148. typedef CommErr (FAR *CDILDecryptionProcPtr)( void FAR *pData, long Count, long refCon ) ;
  149.  
  150. /*
  151. **    These definitions will result in functions that look like the following:
  152. **    
  153. **    void CompletionHook         ( CommErr errorValue, long refCon ) ;
  154. **    void PipeCompletionHook     ( CommErr errorValue, void *pData, Size Count, long refCon, long lFlags ) ;
  155. **    void EncryptHook             ( void *pData, Size Count, long refCon) ;
  156. **    void DecryptHook             ( void *pData, Size Count, long refCon) ;
  157. */
  158.  
  159.         /* ~~~~~~~ CDIL initialization and cleanup methods        */
  160.  
  161. #ifdef __cplusplus
  162. extern "C" {
  163.         CommErr     FAR  CDPipeInit            ( CDILPipe FAR *pipe, const char FAR *connectionType, const char FAR *connectionName, 
  164.                                               char FAR * configInfo, char FAR * pipePort, Size  readSize = kDefaultBufferSize, 
  165.                                               Size  writeSize = kDefaultBufferSize ) ;
  166. #else
  167.         CommErr     FAR  CDPipeInit            ( CDILPipe FAR *pipe, char FAR *connectionType, char FAR *connectionName, char FAR * configInfo,
  168.                                               char FAR * pipePort, Size  readSize, Size  writeSize ) ;
  169. #endif
  170.  
  171.         CommErr     FAR  CDPipeDisconnect    ( CDILPipe FAR *pipe  ) ;
  172. #ifdef __cplusplus
  173.         CommErr        FAR  CDPipeListen         ( CDILPipe FAR *pipe, long timeout = kDefaultTimeout, CDILCompletionProcPtr completionHook = nil, long refCon = 0 ) ;
  174. #else
  175.         CommErr        FAR  CDPipeListen         ( CDILPipe FAR *pipe, long timeout, CDILCompletionProcPtr completionHook, long refCon ) ;
  176. #endif
  177.  
  178.         CommErr        FAR  CDPipeAccept         ( CDILPipe FAR *pipe  ) ;
  179. #ifdef __cplusplus
  180.         CommErr        FAR  CDPipeAbort         ( CDILPipe FAR *pipe, CDILPipeDirection direction = kAllPipes ) ;
  181. #else
  182.         CommErr        FAR  CDPipeAbort         ( CDILPipe FAR *pipe, CDILPipeDirection direction ) ;
  183. #endif
  184.  
  185.         /* ~~~~~~~ CDIL read and write methods                    */
  186.  
  187. #ifdef __cplusplus
  188.         CommErr     FAR  CDPipeRead        ( CDILPipe FAR *pipe, void FAR * p, long FAR * count, Boolean FAR * eom, long swapSize = 0, 
  189.                                             long destEncoding = 0, long timeOut = 0, CDILPipeCompletionProcPtr completionHook = nil, 
  190.                                             long refCon = 0) ;
  191.         CommErr     FAR  CDBytesInPipe    ( CDILPipe FAR *pipe, CDILPipeDirection direction, long FAR *count ) ;
  192.         CommErr     FAR  CDPipeWrite    ( CDILPipe FAR *pipe, void FAR * p, long FAR * count, Boolean eom = true, long swapSize = 0, long srcEncoding = 0, 
  193.                                                  long timeOut = 0, CDILCompletionProcPtr completionHook = nil, long refCon = 0) ;
  194. #else
  195.         CommErr     FAR  CDPipeRead        ( CDILPipe FAR *pipe, void FAR * p, long FAR * count, Boolean FAR * eom, long swapSize, long destEncoding, 
  196.                                                  long timeOut, CDILPipeCompletionProcPtr completionHook, long refCon) ;
  197.         CommErr     FAR  CDBytesInPipe    ( CDILPipe FAR *pipe, CDILPipeDirection direction, long FAR *count ) ;
  198.         CommErr     FAR  CDPipeWrite    ( CDILPipe FAR *pipe, void FAR * p, long FAR* count, Boolean eom, long swapSize, long srcEncoding, 
  199.                                                 long timeOut, CDILCompletionProcPtr completionHook, long refCon) ;
  200. #endif
  201.  
  202.  
  203.         /* ~~~~~~~ CDIL maintenance methods                        */
  204.  
  205.         void        FAR  CDIdle             ( CDILPipe FAR *pipe ) ;
  206.         CDIL_State    FAR  CDGetPipeState     ( CDILPipe FAR *pipe  ) ;
  207.         CommErr        FAR  CDSetPipeState        ( CDILPipe FAR *pipe, CDIL_State user_state ) ;
  208.  
  209.         /* ~~~~~~~ CDIL encryption definition methods                */
  210.  
  211.         void        FAR  CDEncryptFunction    ( CDILPipe FAR *pipe, CDILEncryptionProcPtr encryptFunction, long refCon ) ;
  212.         void        FAR  CDDecryptFunction    ( CDILPipe FAR *pipe, CDILDecryptionProcPtr decryptFunction, long refCon ) ;
  213.  
  214.         /* ~~~~~~~ CDIL Information methods                        */
  215.         char FAR *     FAR  CDGetConfigStr     ( CDILPipe FAR *pipe ) ;
  216.         char FAR *    FAR  CDGetPortStr         ( CDILPipe FAR *pipe ) ;
  217.         long          FAR  CDGetTimeout              ( CDILPipe FAR *pipe ) ;
  218. #ifndef forMac
  219.         void         FAR  CDSetApplication   ( CDILPipe FAR *pipe, short appInstance );
  220. #endif
  221.         /* ~~~~~~~ CDIL advanced methods                            */
  222.         
  223.         CommErr     FAR  CDFlush                     ( CDILPipe FAR *pipe, CDILPipeDirection direction ) ;
  224.         void             FAR  CDPad                         ( CDILPipe FAR *pipe, long length ) ;
  225.         void            FAR  CDSetPadState        ( CDILPipe FAR *pipe, Boolean  paddingOn ) ;
  226. #ifdef __cplusplus
  227.     }    //    extern "C"
  228. #endif
  229.  
  230. /*-------------------------------------------------------------------------
  231. **        Basic functions
  232. **            These functions are used at application startup or shutdown to 
  233. **            perform global preparation/cleanup of the DIL environment.
  234. ** ------------------------------------------------------------------------ */
  235.  
  236. #ifdef __cplusplus
  237. extern "C" {
  238. #endif
  239.         CommErr     FAR CDInitCDIL                         ( void ) ; 
  240.         CommErr     FAR CDDisposeCDIL                 ( void ) ;
  241.         CDILPipe    FAR * CDCreateCDILObject    ( void ) ;
  242.         CommErr        FAR CDDisposeCDILObject     (  CDILPipe FAR *pipe ) ;
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246.  
  247. #endif    /* __CDILPipe_H */
  248.